/**
 * Baijiahulian.com Inc. Copyright (c) 2014-2016 All Rights Reserved.
 */
package com.baijia.authentication.principal.credentials;

import com.baijia.authentication.AccountType;
import com.baijia.authentication.handler.support.encoder.PasswordEncoder;
import com.baijia.authentication.handler.support.encoder.PlainTextPasswordEncoder;
import com.baijia.authentication.principal.Credentials;

/**
 * @title MobileCredentials
 * @desc TODO
 * @author macrohuang
 * @date Mar 31, 2016
 * @version 1.0
 */
public class MobileCredentials extends Credentials {

    private static final long serialVersionUID = -3507089813360225990L;

    private String mobile;
    private String passcode;

    private transient PasswordEncoder encoder;

    public MobileCredentials(String mobile, String passcode) {
        this(mobile, passcode, new PlainTextPasswordEncoder());
    }

    public MobileCredentials(String mobile, String passcode, PasswordEncoder encoder) {
        this.encoder = encoder;
        this.mobile = mobile;
        this.passcode = this.encoder.encode(passcode);
    }

    @Override
    public String getUsername() {
        return mobile;
    }

    public String getPasscode() {
        return this.encoder.decode(passcode);
    }

    public Integer getAccountType() {
        return AccountType.MOBILE.getCode();
    }

    @Override
    public String toString() {
        return "{mobile: " + mobile + ", passcode: ***}";
    }

}